package com.lanhu.designpattern.singleton.lazy;

/**
 * author:zhangzg
 * date:2020/10/31 23:38
 */
public class SingletonLazy {

    private static SingletonLazy singletonLazy = null;

    private SingletonLazy(){}

    /**
     * synchronizedz在方法上，存在性能问题。锁是在类上
     * @return
     */
    public synchronized static SingletonLazy getInstance(){
        if (singletonLazy == null){
            singletonLazy = new SingletonLazy();
        }
        return singletonLazy;
    }

    /**
     * 防止序列化破坏单例
     * @return
     */
    private Object readResolve(){
        return singletonLazy;
    }

}
